﻿using BackData;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Rabbit.API.Application.Command.User;
using Rabbit.API.DTOs;

namespace Rabbit.API.Controllers
{
    /// <summary>
    /// 用户控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UsersController : ControllerBase
    {
        IMediator mediator;

        public UsersController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 用户登录实现  //登录功能已完成 可扩展 加盐 未给别的方法添加JWT [Authorize]特性详解
        /// </summary>
        /// <param name="request">账号密码</param>
        /// <param name="cancellationToken">取消</param>
        /// <returns>用户数据</returns>
        [HttpPost]
        public Task<APIResult<LoginDTO>> UserLogin(UserLoginCommand request)
        {
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 测试JWT配置文件
        /// </summary>
        /// <returns>字符串</returns>
        [HttpPost]
        [Authorize]
        public string TestToKenway()
        {
            return "ToKen配置文件测试成功";
        }
    }
}
